import elementUI from 'element-ui'
import locale from "element-ui/lib/locale"
import en from "element-ui/lib/locale/lang/en"
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import Vue from 'vue'
let apiBaseURL =process.env.NODE_ENV === 'production'? "/webApi/":"/webApi/"
let apiBaseUploadUrl=process.env.NODE_ENV === 'production'? "/doUpload/":"/doUpload/"  //附件上传的
// 网站地址
let URL = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/
//设置好需要的校验规则
let inputRules = {
  telephone: {
    pattern: /^1[3-9]\d{9}$/,
    message: '手机号格式错误',
    trigger: 'blur'
  },
  phone: {
    pattern: /^\d{10,12}$/,
    message: '座机号格式错误',
    trigger: 'blur'
  },
  QQ: {
    pattern: /^[1-9][0-9]{4,14}$/,
    message: 'QQ格式错误',
    trigger: 'blur'
  },
  mail: {
    pattern: /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/,
    message: '邮箱格式错误',
    trigger: 'blur'
  }
}


// 邮编正则
let postCode = /^[1-9][0-9]{5}$/
// 手机号正则
let phoneReg = /^1[3|4|5|6|7|8][0-9]\d{4,8}$/;
// 邮箱正则
let emailReg = /\w@\w*\.\w/

function delConfirm(title, btnText, cancelBtn) {
  return new Promise((resolve) => {
    elementUI.MessageBox.confirm(title || "您确定进行此操作",'提示', {
      confirmButtonText: btnText || '确定',
      cancelButtonText: cancelBtn || '取消',
      type: "warning"
    }).then(res => {
      resolve(true);
    }).catch(err => {
      resolve(false);
    });
  });
}
// 切换element框架语言包
function changeElementLang() {
  console.log($store.state.langage, "是公共")
  if ($store.state.langage == 'en') {
    locale.use(en);
  } else {
    locale.use(zhLocale);
  }
}

export default {
  apiBaseURL,
  apiBaseUploadUrl,
  URL,
  delConfirm,
  postCode,
  phoneReg,
  emailReg,
  inputRules,
  changeElementLang
}
